$(document).ready(function(){
	$(".btn_reject").bind("click", function(e){
		var transactionId = $(this).attr("data-reject");
		$("#popup_reject").fadeIn("fast", function(){
			$.ajax({ 
		        type: 'get', 
		        url: 'rejectTransaction', 
		        data: {
		        	transactionId : transactionId,
		        },
		        dataType: 'json',
		        success: function (data) { 
					console.log(data);
					$("#idTransactionReject").val(data.transaction.idTransaction);
					
					$(".message").html(data.message);
					$(".error").html(data.error);
					$(".validation").html(data.validation);
					
					$(".idTransaction").html(data.transaction.idTransaction);
					$(".transactionType").html(data.transaction.transactionType);
					$(".transactionStatus").html(data.transaction.transactionStatus);
					$(".changeAmount").html(data.transaction.changeAmount);
					
					var date = new Date(data.transaction.beginTime);
					document.getElementById("beginTimeReject").innerHTML = date;
					$(".userSupport").html(data.transaction.userSupport.userName);
		        },
		        error:function(XMLHttpRequest, textStatus, errorThrown) { 
		        	console.log("errorTest", textStatus, errorThrown, XMLHttpRequest); 
		        	$("#errorTest").html(XMLHttpRequest.responseText);
		        }
		    });
		}); 	
	});
	
	$("#btn_reject_complete").bind("click", function(e){
		$("#popup_reject").fadeOut();
		$("#popup_reject_complete").fadeIn("fast",function(){
			$.ajax({ 
				type: 'post', 
				url: 'rejectTransactionComplete', 
				data:{
					idTransactionReject: $("#idTransactionReject").val(),
					comment: $("[name='comment']").val(), 
				},
				dataType: 'json',
				success: function (data) { 
					$(".message").html(data.message);
					$(".error").html(data.error);
					$(".validation").html(data.validation);
					idTransaction = data.transaction.idTransaction;
				},
				error:function(e) { 
					console.log(e);
					$(".test_error").html(e.responseText);
				}
			});
		});
	});
	
	$("#btn_reject_cancel").bind("click", function(e){
		$("#popup_reject").fadeOut();
	});
	
	$("#btn_reject_close").bind("click", function(e){
		$("#popup_reject_complete").fadeOut();
		$("[data-reject='" + idTransaction + "']").closest("tr").remove();
	});
});